home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Papers / OS Shell in Java / Facade / Desktop.java < prev    next >
Encoding:
Java Source  |  1998-06-18  |  62.6 KB  |  1,833 lines  |  [TEXT/dosa]

  1. //    Desktop.java : this is a Java source code file for the program Facade.
  2. //    Copyright 1998, Andrew S. Downs
  3. //    andrew.downs@tulane.edu
  4. //
  5. //    This source code is distributed as freeware.
  6. //    Just keep this author information in the file.  Enjoy!
  7.  
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import java.awt.image.*;
  11. import java.io.*;
  12. import java.net.*;
  13. import java.util.*;
  14. import com.sun.java.swing.*;
  15.  
  16. public class Desktop extends Window implements Serializable, MouseListener, MouseMotionListener, TimerEventListener {
  17.     transient boolean bSplash = false, firstRepaint = true, dragInProgress = false;
  18.  
  19.     transient int delay;
  20.     transient int menuBarHeight;
  21.     transient int res;
  22.     transient int IMG_SPLASH = 0;
  23.     transient int IMG_APPLE = 1;
  24.     transient int IMG_TRASH = 2;
  25.     transient int IMG_TRASH_FULL = 3;
  26.     transient int IMG_TRASH_MASK = 8;
  27.     transient int IMG_TRASH_FULL_MASK = 11;
  28.     transient int IMG_DRIVE_MASK = 9;
  29.     transient int IMG_TRASH_STATIC = 10;
  30.     transient int IMG_DRIVE = 4;
  31.     transient int IMG_DOC = 5;
  32.     transient int IMG_FOLDER = 6;
  33.     transient int IMG_UP_ARROW = 7;
  34.     transient int activeMenu = -1, activeMenuItem = -1;
  35.     transient int initialX = 0;
  36.     transient int initialY = 0;
  37.  
  38.     transient Dimension d;
  39.  
  40.     transient DesktopMenuBar dmb;
  41.     transient DesktopImage imgSplash, imgFolder, imgDriveMask, imgTrashStatic, imgTrash, imgTrashMask, imgTrashFull, imgTrashFullMask, imgDrive, imgApple;//, imgTrash, imgTrashFull, imgDrive, imgDoc, imgFolder;
  42.     transient DesktopImage dragItem = new DesktopImage();
  43.     transient DesktopImage highlightedImage = new DesktopImage();
  44.     
  45.     transient Font menuFont, iconFont;
  46.     
  47.     transient Rectangle activeMenuRect = new Rectangle( -1, -1, 0, 0 );
  48.     transient Rectangle activeMenuItemRect = new Rectangle( -1, -1, 0, 0 );
  49.     transient static Rectangle tempClipRect = new Rectangle( -1, -1, 0, 0 );
  50.     
  51.     transient String fileSep, pathSep, lineSep;
  52.  
  53.     transient Toolkit tk = Toolkit.getDefaultToolkit();
  54.  
  55.     Vector vectorImages = new Vector();
  56.     static Vector vectorIcons = new Vector();
  57.     transient Vector vectorMenus = new Vector();
  58.     static Vector vectorWindows = new Vector();
  59.     Vector vectorJunk = new Vector();
  60.     public static Vector vectorUtil = new Vector();    
  61.     transient Vector trash = new Vector();
  62.  
  63.     Image offscreenImage;
  64.     Graphics g;
  65.  
  66.     Desktop() {
  67.         // General setup.
  68.         super( new Frame() );
  69.         this.setLayout( null );
  70.         this.setBackground( Color.lightGray );
  71.         this.menuFont = new Font( "Dialog", Font.BOLD, 12 );
  72.         this.iconFont = new Font( "SansSerif", Font.PLAIN, 12 );
  73.         this.setFont( this.menuFont );
  74.  
  75.     DesktopImage imgDoc;
  76.  
  77.         // Initialize instance variables.
  78.         this.fileSep = Global.fileSep;
  79.         this.bSplash = true;
  80.         imgSplash = new DesktopImage();
  81.         imgApple = new DesktopImage();
  82.         imgTrash = new DesktopImage();
  83.         imgDrive = new DesktopImage();
  84.         imgTrashFull = new DesktopImage();
  85.         imgDoc = new DesktopImage();
  86.         imgFolder = new DesktopImage();
  87.         imgDriveMask = new DesktopImage();
  88.         imgTrashMask = new DesktopImage();
  89.         imgTrashFullMask = new DesktopImage();
  90.         
  91.         MediaTracker mt = new MediaTracker( this );
  92.         URL u;
  93.  
  94.         // Get splash image.
  95.         try {
  96.             u = this.getClass().getResource( Global.splashString );
  97.             imgSplash.setImage( this.createImage( ( ImageProducer )( u.getContent() ) ) );
  98.             mt.addImage( imgSplash.getImage(), IMG_SPLASH );
  99.  
  100.             mt.waitForID( IMG_SPLASH );
  101.  
  102.             imgSplash.setX( this.getX() + ( ( this.getWidth() / 2 ) - ( imgSplash.getImage().getWidth( this ) / 2 ) ) );
  103.             imgSplash.setY( this.getY() + ( ( this.getHeight() / 2 ) - ( imgSplash.getImage().getHeight( this ) / 2 ) ) );
  104.         }
  105.         catch ( MalformedURLException e ) {
  106.             System.out.println( "MalformedURLException" );
  107.         }
  108.         catch ( IOException e ) {
  109.             System.out.println( "IOException" );
  110.         }
  111.         catch ( InterruptedException e ) {
  112.             System.out.println( "InterruptedException" );
  113.         }
  114.  
  115.         // Set Window properties based on screen size.
  116.         res = tk.getScreenResolution();
  117.         d = tk.getScreenSize();
  118.         this.setBounds( Global.defaultX, Global.defaultY, d.width, d.height );
  119.         this.setMenuBarHeight( Global.defaultMenuBarHeight );
  120.         this.setVisible( true );
  121.  
  122.         offscreenImage = createImage( this.getBounds().width, this.getBounds().height );
  123.         g = offscreenImage.getGraphics();
  124.  
  125.         // Display splash screen.
  126.         this.repaint();
  127.         mt.removeImage( imgSplash.getImage(), IMG_SPLASH );
  128.  
  129.         // Get all images.
  130.         try {
  131.             u = this.getClass().getResource( Global.appleString );
  132.             imgApple.setImage( this.createImage( ( ImageProducer )( u.getContent() ) ) );
  133.             mt.addImage( imgApple.getImage(), IMG_APPLE );
  134.  
  135.              u = this.getClass().getResource( Global.trashString );
  136.             imgTrash.setImage( this.createImage( ( ImageProducer )( u.getContent() ) ) );
  137.             mt.addImage( imgTrash.getImage(), IMG_TRASH );
  138.  
  139.                u = this.getClass().getResource( Global.trashFullString );
  140.             imgTrashFull.setImage( this.createImage( ( ImageProducer )( u.getContent() ) ) );
  141.             mt.addImage( imgTrashFull.getImage(), IMG_TRASH_FULL );
  142.  
  143.                u = this.getClass().getResource( Global.driveString );
  144.             imgDrive.setImage( this.createImage( ( ImageProducer )( u.getContent() ) ) );
  145.             mt.addImage( imgDrive.getImage(), IMG_DRIVE );
  146.  
  147.                u = this.getClass().getResource( Global.docString );
  148.             imgDoc.setImage( this.createImage( ( ImageProducer )( u.getContent() ) ) );
  149.             mt.addImage( imgDoc.getImage(), IMG_DOC );
  150.  
  151.                u = this.getClass().getResource( Global.folderString );
  152.             imgFolder.setImage( this.createImage( ( ImageProducer )( u.getContent() ) ) );
  153.             mt.addImage( imgFolder.getImage(), IMG_FOLDER );
  154.  
  155.                u = this.getClass().getResource( Global.trashMaskString );
  156.             imgTrashMask.setImage( this.createImage( ( ImageProducer )( u.getContent() ) ) );
  157.             mt.addImage( imgTrashMask.getImage(), IMG_TRASH_MASK );
  158.  
  159.                u = this.getClass().getResource( Global.trashFullMaskString );
  160.             imgTrashFullMask.setImage( this.createImage( ( ImageProducer )( u.getContent() ) ) );
  161.             mt.addImage( imgTrashFullMask.getImage(), IMG_TRASH_FULL_MASK );
  162.  
  163.                u = this.getClass().getResource( Global.driveMaskString );
  164.             imgDriveMask.setImage( this.createImage( ( ImageProducer )( u.getContent() ) ) );
  165.             mt.addImage( imgDriveMask.getImage(), IMG_DRIVE_MASK );
  166.  
  167. //System.out.println( "Waiting..." );
  168.             mt.waitForAll();
  169. //System.out.println( "Finished waiting." );
  170.  
  171.             imgApple.setX( this.getX() + ( 2 * Global.defaultMenuHSep ) );
  172.             imgApple.setY( this.getY() + Global.defaultMenuItemVSep );
  173.  
  174.             imgTrash.setX( this.getX() + this.getWidth() - ( imgTrash.getImage().getWidth( this ) * 2 ) );
  175.             imgTrash.setY( this.getY() + this.getHeight() - ( imgTrash.getImage().getHeight( this ) * 3 ) );
  176.             imgTrash.setLabel( Global.trashDisplayString );
  177.             imgTrash.setLabelLocation( imgTrash.getX() + ( imgTrash.getImage().getWidth( this ) / 2 ) - ( this.getGraphics().getFontMetrics().stringWidth( imgTrash.getLabel() ) / 2 ), imgTrash.getY() + ( imgTrash.getImage().getHeight( this ) ) + ( this.getGraphics().getFontMetrics().getHeight() ) );
  178.  
  179.             imgTrashFull.setX( imgTrash.getX() );
  180.             imgTrashFull.setY( imgTrash.getY() );
  181.             imgTrashFull.setLabel( Global.trashDisplayString );
  182.             imgTrashFull.setLabelLocation( imgTrash.getX() + ( imgTrash.getImage().getWidth( this ) / 2 ) - ( this.getGraphics().getFontMetrics().stringWidth( imgTrash.getLabel() ) / 2 ), imgTrash.getY() + ( imgTrash.getImage().getHeight( this ) ) + ( this.getGraphics().getFontMetrics().getHeight() ) );
  183.             
  184.             imgDrive.setX( this.getX() + this.getWidth() - ( imgDrive.getImage().getWidth( this ) * 2 ) );
  185.             imgDrive.setY( this.getY() + this.menuBarHeight + imgDrive.getImage().getHeight( this ) );
  186.  
  187.             String defaultVolume = System.getProperty( "user.home" );
  188.             
  189.             int loc = 0;
  190.  
  191.             //pathSep sep02
  192.             StringBuffer sb2 = new StringBuffer();
  193.             sb2.append( defaultVolume.charAt( 0 ) );
  194.             int len = defaultVolume.length();
  195.             int m = 0;
  196.             while ( ++m < len ) {
  197.                 sb2.append( defaultVolume.charAt( m ) );
  198.  
  199.                 if ( ( defaultVolume.charAt( m ) == Global.sep02 ) || ( defaultVolume.charAt( m ) == Global.sep01 ) )
  200.                     break;
  201.             }
  202.  
  203. //System.out.println( "Got this far..." );
  204. /*
  205.             // Parse root volume name.
  206.             loc = defaultVolume.indexOf( Global.fileSep );
  207.             
  208.             // Volume name includes first '\'.
  209.             // Rework this for MacOS.
  210.             if ( loc > 0 )
  211. {//            if ( ( loc > 0 ) && ( loc < defaultVolume.length() ) )
  212.                 defaultVolume = new String( defaultVolume.substring( 0, loc - 1 ) );
  213. //                defaultVolume = defaultVolume.substring( 0, loc + 1 );
  214. System.out.println( Global.fileSep );
  215. }    
  216.             
  217.             // Parse root volume name.
  218.             loc = defaultVolume.indexOf( Global.pathSep );
  219.  
  220.             // Volume name includes first '\'.
  221.             // Rework this for MacOS.
  222.             if ( loc > 0 )
  223. {//            if ( ( loc > 0 ) && ( loc < defaultVolume.length() ) )
  224.                 defaultVolume = new String( defaultVolume.substring( 0, loc - 1 ) );
  225. //                defaultVolume = defaultVolume.substring( 0, loc + 1 );
  226. System.out.println( Global.pathSep );
  227. }    
  228.             // Parse root volume name.
  229.             loc = defaultVolume.indexOf( Global.sep01 );
  230.             
  231.             // Volume name includes first '\'.
  232.             // Rework this for MacOS.
  233.             if ( loc > 0 )
  234. {//            if ( ( loc > 0 ) && ( loc < defaultVolume.length() ) )
  235.                 defaultVolume = new String( defaultVolume.substring( 0, loc - 1 ) );
  236. //                defaultVolume = defaultVolume.substring( 0, loc + 1 );
  237. System.out.println( Global.sep01 );
  238. }    
  239.             
  240.             // Parse root volume name.
  241.             loc = defaultVolume.indexOf( Global.sep02 );
  242.             
  243.             // Volume name includes first '/'.
  244.             // Rework this for MacOS.
  245.             if ( loc > 0 )
  246. {//            if ( ( loc > 0 ) && ( loc < defaultVolume.length() ) )
  247.                 defaultVolume = new String( defaultVolume.substring( 0, loc - 1 ) );
  248. //                defaultVolume = defaultVolume.substring( 0, loc + 1 );
  249. System.out.println( Global.sep02 );
  250. }    
  251.     
  252.             // Parse root volume name.
  253.             loc = defaultVolume.indexOf( Global.sep03 );
  254.             
  255.             // Volume name includes first '/'.
  256.             // Rework this for MacOS.
  257.             if ( loc > 0 )
  258. {//            if ( ( loc > 0 ) && ( loc < defaultVolume.length() ) )
  259.                 defaultVolume = new String( defaultVolume.substring( 0, loc - 1 ) );
  260. //                defaultVolume = defaultVolume.substring( 0, loc + 1 );
  261. System.out.println( Global.sep03 );
  262. }    
  263. */
  264.             defaultVolume = sb2.toString();
  265.             imgDrive.setPath( "\\" );
  266. //            imgDrive.setPath( defaultVolume );
  267.         
  268. /*
  269.             // Remove leading '\' character.
  270.             loc = defaultVolume.indexOf( Global.sep01 );
  271.  
  272.             if ( loc == 0 ) {
  273.                 defaultVolume = new String( defaultVolume.substring( 1 ) );
  274.             }
  275.             
  276.             // Remove leading '/' character.
  277.             loc = defaultVolume.indexOf( Global.sep02 );
  278.  
  279.             if ( loc == 0 ) {
  280.                 defaultVolume = new String( defaultVolume.substring( 1 ) );
  281.             }
  282. */
  283.             sb2 = new StringBuffer();
  284.             len = defaultVolume.length();
  285.             m = 0;
  286.             while ( m < len ) {
  287.                 if ( ( defaultVolume.charAt( m ) != Global.sep02 ) && ( defaultVolume.charAt( m ) != Global.sep01 ) )
  288.                     sb2.append( defaultVolume.charAt( m ) );
  289.  
  290.                 m++;
  291.             }
  292.             
  293.             defaultVolume = sb2.toString();
  294.             
  295.             // Volume name includes first '%20'.
  296.             // Rework this for MacOS.
  297.             loc = defaultVolume.indexOf( Global.spaceSep );
  298.  
  299.             while ( ( loc >= 0 ) && ( loc < defaultVolume.length() ) ) {
  300.                 String s1 = new String( defaultVolume.substring( 0, loc ) );
  301.                 String s2 = new String( defaultVolume.substring( loc + Global.spaceSep.length() ) );
  302.                 defaultVolume = new String( s1 + " " + s2 );
  303.                 loc = defaultVolume.indexOf( Global.spaceSep );
  304.             }
  305.  
  306.             imgDrive.setLabel( defaultVolume );
  307.             imgDrive.setLabelLocation( imgDrive.getX() + ( imgDrive.getImage().getWidth( this ) / 2 ) - ( this.getGraphics().getFontMetrics().stringWidth( imgDrive.getLabel() ) / 2 ), imgDrive.getY() + ( imgDrive.getImage().getHeight( this ) ) + ( this.getGraphics().getFontMetrics().getHeight() ) );
  308.  
  309. //System.out.println( "Calling doDelay()..." );
  310.             
  311. //            this.doDelay();
  312. //System.out.println( "Finished calling doDelay()..." );
  313.         }
  314.         catch ( MalformedURLException e ) {
  315.             System.out.println( "MalformedURLException" );
  316.         }
  317.         catch ( IOException e ) {
  318.             System.out.println( "IOException" );
  319.         }
  320.         catch ( InterruptedException e ) {
  321.             System.out.println( "InterruptedException" );
  322.         }
  323.  
  324.         vectorImages.addElement( imgTrash );
  325.         vectorImages.addElement( imgDrive );
  326. //        vectorImages.addElement( imgFolder );
  327. //        vectorImages.addElement( imgUpArrow );
  328.  
  329.         vectorUtil.addElement( imgDoc );
  330.         vectorUtil.addElement( imgFolder );
  331.         vectorUtil.addElement( imgTrashMask );
  332.         vectorUtil.addElement( imgDriveMask );
  333.         vectorUtil.addElement( imgTrashFull );
  334.         vectorUtil.addElement( imgTrash );
  335.         vectorUtil.addElement( imgTrashFullMask );
  336.  
  337.         DesktopFolder.setImage( imgFolder.getImage() );
  338.         DesktopDoc.setImage( imgDoc.getImage() );
  339.  
  340. //System.out.println( "Checking the trash..." );
  341.         // Initialize the trash.
  342.         if ( !this.checkTrashExists() )
  343.             this.createTrashDir();
  344.         
  345.         // If the trash is full, set the proper icon.
  346.         DesktopImage di = ( ( DesktopImage )this.vectorImages.elementAt( 0 ) );
  347.         String path = di.getPath();
  348.         File f = new File( path );
  349.         if ( f.exists() ) {
  350.             String array[] = f.list();
  351.                 
  352.             if ( ( array != null ) && ( array.length > 0 ) )
  353.                 this.vectorImages.setElementAt( this.imgTrashFull, 0 );
  354.         }
  355.  
  356.         this.imgTrashFull.setPath( di.getPath() );
  357. //System.out.println( "About to restore state." );
  358.  
  359.         this.restoreState();
  360.  
  361.         this.setupMenuBar();
  362.  
  363.         // Setup event listeners.
  364.         this.addMouseListener( ( MouseListener )this );
  365.         this.addMouseMotionListener( ( MouseMotionListener )this );
  366.         
  367.         this.bSplash = false;
  368.         this.repaint();
  369.         //this.redrawOpenFrames();
  370.     }
  371.  
  372.     public void setupMenuBar() {
  373.         Graphics g = this.getGraphics();
  374.         FontMetrics theFontMetrics = g.getFontMetrics();
  375.         
  376.         dmb = new DesktopMenuBar();
  377.         
  378. // Changed.
  379. //        dmb.setParentObj( this );
  380.  
  381. //        dmb = new DesktopMenuBar( this.getGraphics() );
  382. //        this.add( dmb );
  383.         dmb.setBounds( this.getBounds().x, this.getBounds().y, this.getBounds().width, Global.defaultMenuBarHeight );
  384. //        dmb.setBounds( this.getBounds().x, this.getBounds().y, this.getBounds().width, this.getBounds().height );
  385.         dmb.setBackground( Color.white );
  386.         dmb.setForeground( Color.black );
  387.         
  388. // Changed.
  389. //        dmb.setGraphics( this.getGraphics() );
  390.         
  391.         // Create menus and their menu items.
  392.         DesktopImageMenu dim;
  393.         Vector vectorMenuItems;
  394.         DesktopMenuItem dmi;
  395.  
  396.         int newY = this.getY() + this.getMenuBarHeight() - ( this.getMenuBarHeight() / 3 );
  397.         
  398.         int newX = this.getX();
  399. //        newX += Global.defaultMenuHSep;
  400.  
  401.         // Create Apple menu.
  402.         dim = new DesktopImageMenu();
  403.         dim.setImage( imgApple.getImage() );
  404.         dim.setX( imgApple.getX() );
  405.         dim.setY( imgApple.getY() );
  406.         dmi = new DesktopMenuItem( Global.menuItemAboutMac );
  407.         dmi.setEnabled( false );
  408.         dim.getVector().addElement( dmi );
  409.         dim.setItemLocations( this.getGraphics().getFontMetrics() );
  410.         dmb.getVector().addElement( dim );
  411.         
  412.         newX = imgApple.getX();
  413.         newX += ( 2 * Global.defaultMenuHSep );
  414.         newX += ( ( DesktopImageMenu )dmb.getVector().elementAt( 0 ) ).getImage().getWidth( this );
  415.  
  416.         DesktopMenu dm;
  417.  
  418.         // Create File menu.
  419.         dm = new DesktopMenu();
  420.         dm.setLabel( Global.menuFile );
  421.         dm.setX( newX );
  422.         dm.setY( newY );
  423.         dmi = new DesktopMenuItem( Global.menuItemNew );
  424.         dmi.setEnabled( true );
  425.         dm.getVector().addElement( dmi );
  426.         dmi = new DesktopMenuItem( Global.menuItemOpen );
  427.         dmi.setEnabled( false );
  428.         dm.getVector().addElement( dmi );
  429.         dmi = new DesktopMenuItem( Global.menuItemClose );
  430.         dmi.setEnabled( false );
  431.         dm.getVector().addElement( dmi );
  432.  
  433.         dm.setItemLocations( this.getGraphics().getFontMetrics() );
  434.         dmb.getVector().addElement( dm );
  435.  
  436.         newX += ( 2 * Global.defaultMenuHSep );
  437.         newX += theFontMetrics.stringWidth( dm.getLabel() );
  438.  
  439.         // Create Edit menu.
  440.         dm = new DesktopMenu();
  441.         dm.setLabel( Global.menuEdit );
  442.         dm.setX( newX );
  443.         dm.setY( newY );
  444.         dmi = new DesktopMenuItem( Global.menuItemCut );
  445.         dmi.setEnabled( false );
  446.         dm.getVector().addElement( dmi );
  447.         dmi = new DesktopMenuItem( Global.menuItemCopy );
  448.         dmi.setEnabled( false );
  449.         dm.getVector().addElement( dmi );
  450.         dmi = new DesktopMenuItem( Global.menuItemPaste );
  451.         dmi.setEnabled( false );
  452.         dm.getVector().addElement( dmi );
  453.  
  454.         dm.setItemLocations( this.getGraphics().getFontMetrics() );
  455.         dmb.getVector().addElement( dm );
  456.  
  457.         newX += ( 2 * Global.defaultMenuHSep );
  458.         newX += theFontMetrics.stringWidth( dm.getLabel() );
  459.  
  460.         // Create Special menu.
  461.         dm = new DesktopMenu();
  462.         dm.setLabel( Global.menuSpecial );
  463.         dm.setX( newX );
  464.         dm.setY( newY );
  465.         dmi = new DesktopMenuItem( Global.menuItemEmptyTrash );
  466.         dmi.setEnabled( false );
  467.         dm.getVector().addElement( dmi );
  468.         dmi = new DesktopMenuItem( Global.menuSep );
  469.         dmi.setEnabled( false );
  470.         dm.getVector().addElement( dmi );
  471.         dmi = new DesktopMenuItem( Global.menuItemRestart );
  472.         dmi.setEnabled( true );
  473.         dm.getVector().addElement( dmi );
  474.         dmi = new DesktopMenuItem( Global.menuItemShutdown );
  475.         dmi.setEnabled( true );
  476.         dm.getVector().addElement( dmi );
  477.  
  478.         dm.setItemLocations( this.getGraphics().getFontMetrics() );
  479.         dmb.getVector().addElement( dm );
  480.     
  481.     }
  482.     
  483.     public boolean unhighlightMenuItem( MouseEvent e ) {
  484.         boolean eventHandled = false;
  485.         Graphics g = this.getGraphics();
  486.         FontMetrics theFontMetrics = g.getFontMetrics();
  487.  
  488.         // Handle unhighlighting.
  489.         if ( this.activeMenu != -1 ) {
  490.             // Get menu object.
  491.             int i = this.activeMenu;
  492.             DesktopMenu d = ( DesktopMenu )dmb.getVector().elementAt( i );
  493.             
  494.             // Get menu item vector.
  495.             Vector v = d.getVector();
  496.  
  497.             // Unhighlight current menu item.
  498.             // If Point is outside menu item, redraw the menu item.
  499.             if ( this.activeMenuItem != -1 )  {
  500.                 if ( !activeMenuItemRect.contains( e.getX(), e.getY() ) ) {
  501.                     // Redraw menu background behind this menu item.
  502.                     g.setColor( dmb.getBackground() );
  503.                     g.fillRect( activeMenuItemRect.x, activeMenuItemRect.y, activeMenuItemRect.width, activeMenuItemRect.height );
  504.  
  505.                     // Redraw menu item.
  506.                     g.setColor( Color.black );
  507.                     if ( !( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getEnabled() )
  508.                         g.setColor( Color.lightGray );
  509.                     g.drawString( ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getLabel(), ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getDrawPoint().x, ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getDrawPoint().y );
  510.  
  511.                     g.setColor( Color.black );
  512.                     g.drawRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );
  513.                     g.fillRect( d.getItemBounds().getBounds().x + 2, d.getItemBounds().getBounds().y + d.getItemBounds().getBounds().height, d.getItemBounds().getBounds().width, 2 );
  514.                     g.fillRect( d.getItemBounds().getBounds().x + d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().y + 2, 2, d.getItemBounds().getBounds().height );
  515.  
  516.                     // New menu means no previous selection.
  517.                     this.activeMenuItem = -1;
  518.                     activeMenuItemRect = new Rectangle( -1, -1, 0, 0 );
  519.  
  520.                     eventHandled = true;
  521.                 }
  522.             }
  523.         }
  524.         
  525.         return eventHandled;
  526.     }
  527.  
  528.     public boolean unhighlightMenu( MouseEvent e ) {
  529.         boolean eventHandled = false;
  530.         Graphics g = this.getGraphics();
  531.         FontMetrics theFontMetrics = g.getFontMetrics();
  532.  
  533.         // Handle unhighlighting.
  534.         if ( this.activeMenu != -1 ) {
  535.             // Get menu object.
  536.             int i = this.activeMenu;
  537.             DesktopMenu d = ( DesktopMenu )dmb.getVector().elementAt( i );
  538.             
  539.             // Get menu item vector.
  540.             Vector v = d.getVector();
  541.  
  542.             // Unhighlight current menu.
  543.             // If Point is outside menu, redraw the menu.
  544.             if ( !activeMenuRect.contains( e.getX(), e.getY() ) ) {
  545.                 if ( ( e.getX() < d.getItemBounds().getBounds().x ) || ( e.getX() > ( d.getItemBounds().getBounds().x + d.getItemBounds().width ) ) 
  546.                 || ( e.getY() < d.getItemBounds().getBounds().y ) || ( e.getY() > d.getItemBounds().getBounds().y + d.getItemBounds().getBounds().height ) ) {
  547. /*
  548.                 if ( ( e.getX() < d.getX() - Global.defaultMenuHSep ) || ( e.getX() > ( d.getX() + d.getItemBounds().width ) ) 
  549.                 || ( e.getY() < this.getY() + this.getMenuBarHeight() + ( ( activeMenuItem ) * theFontMetrics.getHeight() ) ) || ( e.getY() > this.getY() + this.getMenuBarHeight() + ( ( activeMenuItem + 1 ) * theFontMetrics.getHeight() ) ) ) {
  550. */
  551.                     // Redraw menubar background behind this menu.
  552.                     g.setColor( dmb.getBackground() );
  553.                     g.fillRect( activeMenuRect.x, activeMenuRect.y, activeMenuRect.width, activeMenuRect.height );
  554.  
  555.                     // Draw menu String or Image.
  556.                     g.setColor( Color.black );
  557.                     if ( d.getLabel() != null )
  558.                         g.drawString( d.getLabel(), d.getX(), d.getY() );
  559.                     else
  560.                         g.drawImage( ( ( DesktopImageMenu )d ).getImage(), d.getX(), d.getY(), this );
  561.                         
  562.                     // Redraw desktop background behind this menu.
  563.                     g.setColor( Color.lightGray );
  564.                     g.fillRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );
  565.  
  566.                     g.drawRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );
  567.                     g.fillRect( d.getItemBounds().getBounds().x + 2, d.getItemBounds().getBounds().y + d.getItemBounds().getBounds().height, d.getItemBounds().getBounds().width, 2 );
  568.                     g.fillRect( d.getItemBounds().getBounds().x + d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().y + 2, 2, d.getItemBounds().getBounds().height );
  569.                     
  570.                     // New menu means no previous selection.
  571.                     this.activeMenu = -1;
  572.                     this.activeMenuItem = -1;
  573.                     activeMenuRect = new Rectangle( -1, -1, 0, 0 );
  574.                     activeMenuItemRect = new Rectangle( -1, -1, 0, 0 );
  575.  
  576.                     eventHandled = true;
  577.                 }
  578.             }
  579.         }
  580.         
  581.         return eventHandled;
  582.     }
  583.     
  584.     public boolean highlightMenuItem( MouseEvent e ) {
  585.         boolean eventHandled = false;
  586.         Graphics g = this.getGraphics();
  587.         FontMetrics theFontMetrics = g.getFontMetrics();
  588.  
  589.         // Handle highlighting.
  590.         if ( this.activeMenu != -1 ) {
  591.             // Get menu object.
  592.             int i = this.activeMenu;
  593.             DesktopMenu d = ( DesktopMenu )dmb.getVector().elementAt( i );
  594.             
  595.             // Get menu item vector.
  596.             Vector v = d.getVector();
  597.  
  598.             // Highlight current menu item.
  599.             // If Point is inside menu item, redraw the menu item.
  600.             // This is the current menu rect.  Replace this if().
  601.             if ( ( e.getX() >= d.getX() - Global.defaultMenuHSep ) && ( e.getX() <= ( d.getX() + ( d.getLabel() == null ? ( ( DesktopImageMenu )d ).getImage().getWidth( this ) : theFontMetrics.stringWidth( d.getLabel() ) ) + Global.defaultMenuHSep ) ) 
  602.             && ( e.getY() >= this.getY() + this.getMenuBarHeight() ) && ( e.getY() <= this.getY() + this.getMenuBarHeight() +  ( v.size() * theFontMetrics.getHeight() ) ) ) {
  603.                 for ( int j = 0; j < v.size(); j++ ) {
  604.                     if ( !( ( DesktopMenuItem )v.elementAt( j ) ).getEnabled() )
  605.                         continue;
  606.                     Rectangle r = new Rectangle( ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().x, ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().y, ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().width, ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().height );
  607.                     if ( r.getBounds().contains( e.getX(), e.getY() ) ) {
  608.                         if ( activeMenuItem != -1 && !activeMenuItemRect.contains( e.getX(), e.getY() ) ) {
  609.                             // Redraw menu background behind this menu item.
  610.                             g.setColor( dmb.getBackground() );
  611.                             g.fillRect( activeMenuItemRect.x, activeMenuItemRect.y, activeMenuItemRect.width, activeMenuItemRect.height );
  612.  
  613.                             // Redraw menu item.
  614.                             g.setColor( Color.black );
  615.                             if ( !( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getEnabled() )
  616.                                 g.setColor( Color.lightGray );
  617.                             g.drawString( ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getLabel(), ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getDrawPoint().x, ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getDrawPoint().y );
  618.                         }
  619.  
  620.                         // Draw menu item background.
  621.                         g.setColor( Color.blue );
  622.                         activeMenuItemRect = new Rectangle( ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().x - Global.defaultMenuHSep + 1, ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().y, ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().width - 1, ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().height );
  623. //                        activeMenuItemRect = new Rectangle( ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().x - Global.defaultMenuHSep, ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().y, ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().width, ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().height );
  624.                         g.fillRect( activeMenuItemRect.x, activeMenuItemRect.y, activeMenuItemRect.width, activeMenuItemRect.height );
  625.  
  626.                         // Draw menu item.
  627.                         g.setColor( dmb.getBackground() );
  628.                         g.drawString( ( ( DesktopMenuItem )v.elementAt( j ) ).getLabel(), ( ( DesktopMenuItem )v.elementAt( j ) ).getDrawPoint().x, ( ( DesktopMenuItem )v.elementAt( j ) ).getDrawPoint().y );
  629.  
  630.                         // Set current menu.
  631.                         this.activeMenuItem = j;
  632.  
  633.                         // Once found, we're done.
  634.                         eventHandled = true;
  635.                         break;
  636.                     }
  637.                 }
  638.             }
  639.         }
  640.         
  641.         return eventHandled;
  642.     }
  643.     
  644.     public boolean highlightMenu( MouseEvent e ) {
  645.         boolean eventHandled = false;
  646.         Graphics g = this.getGraphics();
  647.         FontMetrics theFontMetrics = g.getFontMetrics();
  648.  
  649.         // Handle menus.
  650.         // Highlight current item.
  651.         if ( this.activeMenu == -1 ) {
  652.             for ( int i = 0; i < dmb.getVector().size(); i++ ) {
  653.                 // Get menu object.
  654.                 DesktopMenu d = ( DesktopMenu )dmb.getVector().elementAt( i );
  655.                 
  656.                 // Highlight current menu.
  657.                 // If Point is inside menu, redraw the menu and its items.
  658. //            if ( activeMenuRect.contains( e.getX(), e.getY() ) {
  659.  
  660.                 if ( ( e.getX() >= d.getX() - Global.defaultMenuHSep ) && ( e.getX() <= ( d.getX() + ( d.getLabel() == null ? ( ( DesktopImageMenu )d ).getImage().getWidth( this ) : theFontMetrics.stringWidth( d.getLabel() ) ) + Global.defaultMenuHSep ) ) 
  661.                 && ( e.getY() >= this.getY() ) && ( e.getY() <= this.getMenuBarHeight() ) ) {
  662.  
  663.                     // Draw menubar highlighting.
  664.                     g.setColor( Color.blue );
  665.                     activeMenuRect = new Rectangle( d.getX() - Global.defaultMenuHSep, this.getY(), ( ( d.getLabel() == null ? ( ( DesktopImageMenu )d ).getImage().getWidth( this ) : theFontMetrics.stringWidth( d.getLabel() ) ) ) + ( 2 * Global.defaultMenuHSep ), getMenuBarHeight() );
  666.                     g.fillRect( activeMenuRect.x, activeMenuRect.y, activeMenuRect.width, activeMenuRect.height );
  667.                     
  668.                     // Draw menu String or Image.
  669.                     g.setColor( Color.black );
  670.                     if ( d.getLabel() != null )
  671.                         g.drawString( d.getLabel(), d.getX(), d.getY() );
  672.                     else
  673.                         g.drawImage( ( ( DesktopImageMenu )d ).getImage(), d.getX(), d.getY(), this );
  674.  
  675.                     // Get menu item vector.
  676.                     Vector v = d.getVector();
  677.                     // Draw menu background.
  678.                     g.setColor( dmb.getBackground() );
  679.                     g.fillRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );
  680.  
  681.                     // Draw menu items.
  682.                     
  683.                     for ( int j = 0; j < v.size(); j++ ) {
  684.                         if ( ( ( DesktopMenuItem )v.elementAt( j ) ).getLabel().equals( Global.menuSep ) ) {
  685.                             g.setColor( Color.lightGray );
  686.                             g.fillRect( d.getItemBounds().getBounds().x, ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().y + Global.defaultMenuItemVSep, d.getItemBounds().getBounds().width, 2 );
  687.                             continue;
  688.                         }
  689.                         
  690.                         g.setColor( Color.black );
  691.                         if ( !( ( DesktopMenuItem )v.elementAt( j ) ).getEnabled() )
  692.                             g.setColor( Color.lightGray );
  693.                         g.drawString( ( ( DesktopMenuItem )v.elementAt( j ) ).getLabel(), ( ( DesktopMenuItem )v.elementAt( j ) ).getDrawPoint().x, ( ( DesktopMenuItem )v.elementAt( j ) ).getDrawPoint().y );
  694.                     }
  695.                     
  696.                     g.setColor( Color.black );
  697.                     g.drawRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );
  698.                     g.fillRect( d.getItemBounds().getBounds().x + 2, d.getItemBounds().getBounds().y + d.getItemBounds().getBounds().height, d.getItemBounds().getBounds().width, 2 );
  699.                     g.fillRect( d.getItemBounds().getBounds().x + d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().y + 2, 2, d.getItemBounds().getBounds().height );
  700.  
  701.                     // Set current menu.
  702.                     this.activeMenu = i;
  703.  
  704.                     // Once found, we're done.
  705.                     eventHandled = true;
  706.                     break;
  707.                 }
  708.             }
  709.         }
  710.         
  711.         return eventHandled;
  712.     }
  713.     
  714.     public void mouseDragged( MouseEvent e ) {
  715.         // First, determine if the user has selected a different menu item.
  716.             // Unhighlight current menu item.
  717.         // Second, determine if the user has selected a different menu.
  718.             // Unhighlight current menu.
  719.         // Third, determine if the user has selected a new menu item.
  720.             // Highlight new menu item.
  721.         // Fourth, determine if the user has selected a new menu.
  722.             // Highlight new menu.
  723.  
  724.         Graphics g = this.getGraphics();
  725.         FontMetrics theFontMetrics = g.getFontMetrics();
  726.         boolean eventHandled = false;
  727.  
  728.         if ( this.dragInProgress && ( this.dragItem != null ) ) {
  729.             g.setColor( Color.lightGray );
  730.             g.drawRect( this.dragItem.getBounds().x, this.dragItem.getBounds().y, this.imgFolder.getImage().getWidth( this ), this.imgFolder.getImage().getHeight( this ) );
  731.             this.dragItem.setLocation( e.getX() - this.initialX, e.getY() - this.initialY );
  732.             this.dragItem.setLabelLocation( this.dragItem.getX() + ( this.dragItem.getImage().getWidth( this ) / 2 ) - ( this.getGraphics().getFontMetrics().stringWidth( this.dragItem.getLabel() ) / 2 ), this.dragItem.getY() + ( this.dragItem.getImage().getHeight( this ) ) + ( this.getGraphics().getFontMetrics().getHeight() ) );
  733.             g.setColor( Color.black );
  734.             g.drawRect( this.dragItem.getBounds().x, this.dragItem.getBounds().y, this.imgFolder.getImage().getWidth( this ), this.imgFolder.getImage().getHeight( this ) );
  735.  
  736.             // Draw images.
  737.             Enumeration enum = this.vectorImages.elements();
  738.             int count = 0;
  739.             
  740.             while ( enum.hasMoreElements() ) {
  741.                 DesktopImage d = ( DesktopImage )enum.nextElement();
  742.                 if ( this.dragItem == d  )
  743.                     continue;
  744.                     
  745.                 Rectangle r = new Rectangle( d.getBounds().x, d.getBounds().y, d.getImage().getWidth( this ), d.getImage().getHeight( this ) );
  746.                 if ( r.contains( e.getX(), e.getY() ) ) {
  747.                     if ( this.highlightedImage != null && this.highlightedImage.getImage() != null && this.highlightedImage.getImage() != d.getImage() )
  748.                         g.drawImage( this.highlightedImage.getImage(), this.highlightedImage.getX(), this.highlightedImage.getY(), this );
  749.  
  750.                     if ( count == 0 ) {
  751.                         if ( d.getImage() == this.imgTrash.getImage() )
  752.                             g.drawImage( this.imgTrashMask.getImage(), d.getX(), d.getY(), this );
  753.                         else
  754.                             g.drawImage( this.imgTrashFullMask.getImage(), d.getX(), d.getY(), this );
  755.                     }
  756.                     else if ( count == 1 ) {
  757.                         g.drawImage( this.imgDriveMask.getImage(), d.getX(), d.getY(), this );
  758.                     }
  759.                     
  760.                     this.highlightedImage = d;
  761.                     break;
  762.                 }
  763.                 
  764.                 count++;
  765.             }
  766.         }
  767.  
  768.         eventHandled = this.unhighlightMenuItem( e );
  769. //System.out.println( "unhighlightMenuItem returned " + eventHandled );
  770.  
  771. //        if ( eventHandled )
  772.         eventHandled = this.highlightMenuItem( e );
  773. //System.out.println( "highlightMenuItem returned " + eventHandled );
  774.  
  775. //        if ( !eventHandled )
  776.         eventHandled = this.unhighlightMenu( e );
  777. //System.out.println( "unhighlightMenu returned " + eventHandled );
  778.  
  779. //        if ( eventHandled )
  780.         eventHandled = this.highlightMenu( e );
  781. //System.out.println( "highlightMenu returned " + eventHandled );
  782.  
  783.     }
  784.  
  785.     public void mouseMoved( MouseEvent e ) {
  786.     }
  787.         
  788.     public void mouseClicked( MouseEvent e ) {
  789.         if ( e.getClickCount() == 1 ) {
  790. /*
  791.             for ( int i = 0; i < vectorWindows.size(); i++ ) {
  792.                 DesktopFrame d = ( DesktopFrame )vectorWindows.elementAt( i );
  793.                 Rectangle r = d.getCloseBox();
  794.                 r.setLocation( r.getBounds().x + d.getBounds().x, r.getBounds().y + d.getBounds().y );
  795.                 if ( r.contains( e.getPoint() ) ) {
  796.                     d.setVisible( false );
  797. //                    d.repaint();
  798.                     this.vectorWindows.removeElementAt( i );
  799.                     Graphics g = this.getGraphics();
  800. //    Unchanged.
  801.                     this.repaint();
  802.                     return;
  803.                 }
  804.             }
  805. */
  806.         }
  807.         else if ( e.getClickCount() == 2 ) {
  808.  
  809.             for ( int i = 0; i < vectorImages.size(); i++ ) {
  810.                 DesktopImage d = ( DesktopImage )vectorImages.elementAt( i );
  811.                 Rectangle r = new Rectangle( d.getX(), d.getY(), d.getImage().getWidth( this ), d.getImage().getHeight( this ) );
  812.                 if ( r.contains( e.getPoint() ) ) {
  813.                     boolean found = false;
  814.                     
  815.                     for ( int count = 0; count < this.vectorWindows.size(); count ++ ) {
  816.                         DesktopFrame dwTemp = ( DesktopFrame )this.vectorWindows.elementAt( count );
  817.                         if ( dwTemp.getPath().equals( d.getPath() ) ) {
  818. //System.out.println( "DEBUG: setting top frame from Desktop..." );
  819.                             this.setTopFrame( dwTemp );
  820.                             found = true;
  821.                             break;
  822.                         }
  823.                     }
  824.                     
  825.                     if ( found )
  826.                         break;
  827.                         
  828.                     Graphics g = this.getGraphics();
  829.  
  830.                     DesktopFrame dw = new DesktopFrame( d.getPath() );
  831. //                    DesktopFrame dw = new DesktopFrame();
  832. //                    dw.setBounds( 100, 100, 200, 200 );
  833.                     dw.setLabel( d.getLabel() );
  834.                     dw.setPath( d.getPath() );
  835.                     dw.pack();
  836.                     dw.validate();
  837.                     dw.show();
  838.                     dw.toFront();
  839.                     dw.repaint();
  840.                 }
  841.             }
  842.  
  843.         }
  844.     }
  845.         
  846.     public void mouseEntered( MouseEvent e ) {
  847.     }
  848.         
  849.     public void mouseExited( MouseEvent e ) {
  850.     }
  851.         
  852.     public void mousePressed( MouseEvent e ) {
  853.         // New click means no previous selection.
  854.         this.activeMenu = -1;
  855.         this.activeMenuItem = -1;
  856.  
  857.         Graphics g = this.getGraphics();
  858.         FontMetrics theFontMetrics = g.getFontMetrics();
  859.  
  860.         // Draw images.
  861.         Enumeration enum = this.vectorImages.elements();
  862.  
  863.         while ( enum.hasMoreElements() ) {
  864.             DesktopImage d = ( DesktopImage )enum.nextElement();
  865.             Rectangle r = new Rectangle( d.getBounds().x, d.getBounds().y, d.getImage().getWidth( this ), d.getImage().getHeight( this ) );
  866.             if ( r.contains( e.getX(), e.getY() ) ) {
  867.                 this.initialX = e.getX() - r.getBounds().x;
  868.                 this.initialY = e.getY() - r.getBounds().y;
  869.                 this.dragInProgress = true;
  870.                 this.dragItem = d;
  871.                 return;
  872.             }
  873.         }            
  874.  
  875.         if ( dmb.contains( e.getX(), e.getY() ) ) {
  876.             // Handle menu selection.
  877.             for ( int i = 0; i < dmb.getVector().size(); i++ ) {
  878.                 // Get menu object.
  879.                 DesktopMenu d = ( DesktopMenu )dmb.getVector().elementAt( i );
  880.  
  881.                 // Determine if we're inside this menu.
  882.                 if ( ( e.getX() >= d.getX() - Global.defaultMenuHSep ) && ( e.getX() <= ( d.getX() + ( d.getLabel() == null ? ( ( DesktopImageMenu )d ).getImage().getWidth( this ) : theFontMetrics.stringWidth( d.getLabel() ) ) + Global.defaultMenuHSep ) ) 
  883.                 && ( e.getY() >= this.getY() ) && ( e.getY() <= this.getMenuBarHeight() ) ) {
  884.                     // Draw menubar highlighting.
  885.                     g.setColor( Color.blue );
  886.     //                g.fillRect( d.getX() - Global.defaultMenuHSep, this.getY(), ( d.getLabel() == null ? d.getImage().getWidth( this ) : theFontMetrics.stringWidth( d.getLabel() ) ) + ( 2 * Global.defaultMenuHSep ), getMenuBarHeight() );
  887.                     activeMenuRect = new Rectangle( d.getX() - Global.defaultMenuHSep, this.getY(), ( d.getLabel() == null ? ( ( DesktopImageMenu )d ).getImage().getWidth( this ) : theFontMetrics.stringWidth( d.getLabel() ) ) + ( 2 * Global.defaultMenuHSep ), getMenuBarHeight() );
  888.                     g.fillRect(    activeMenuRect.x, activeMenuRect.y, activeMenuRect.width, activeMenuRect.height );
  889.  
  890.                     // Draw menu String or Image.
  891.                     g.setColor( Color.black );
  892.                     if ( d.getLabel() != null )
  893.                         g.drawString( d.getLabel(), d.getX(), d.getY() );
  894.                     else
  895.                         g.drawImage( ( ( DesktopImageMenu )d ).getImage(), d.getX(), d.getY(), this );
  896.                     
  897.                     // Get menu item vector.
  898.                     Vector v = d.getVector();
  899.  
  900.                     DesktopMenuItem dmi = ( DesktopMenuItem )v.elementAt( 0 );
  901.                     if ( dmi.getLabel().equals( Global.menuItemEmptyTrash ) ) {
  902.                         DesktopImage di = ( ( DesktopImage )this.vectorImages.elementAt( 1 ) );
  903.                         String path = di.getPath();
  904.                         File f = new File( path, Global.trashDisplayString );
  905.                         if ( f.exists() ) {
  906.                             String array[] = f.list();
  907.                             
  908.                             if ( array == null || array.length == 0 )
  909.                                 dmi.setEnabled( false );
  910.                             else
  911.                                 dmi.setEnabled( true );
  912.                         }
  913.                     }
  914.                     
  915.                     // Draw menu background.
  916.                     g.setColor( dmb.getBackground() );
  917.                     g.fillRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );
  918.  
  919.                     // Draw menu items.
  920.                     for ( int j = 0; j < v.size(); j++ ) {
  921.                         if ( ( ( DesktopMenuItem )v.elementAt( j ) ).getLabel().equals( Global.menuSep ) ) {
  922.                             g.setColor( Color.lightGray );
  923.                             g.fillRect( d.getItemBounds().getBounds().x, ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().y + Global.defaultMenuItemVSep, d.getItemBounds().getBounds().width, 2 );
  924.                             continue;
  925.                         }
  926.                         
  927.                         g.setColor( Color.black );
  928.                         if ( !( ( DesktopMenuItem )v.elementAt( j ) ).getEnabled() )
  929.                             g.setColor( Color.lightGray );
  930.                         g.drawString( ( ( DesktopMenuItem )v.elementAt( j ) ).getLabel(), ( ( DesktopMenuItem )v.elementAt( j ) ).getDrawPoint().x, ( ( DesktopMenuItem )v.elementAt( j ) ).getDrawPoint().y );
  931.                     }
  932.  
  933.                     g.setColor( Color.black );
  934.                     g.drawRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );
  935.                     g.fillRect( d.getItemBounds().getBounds().x + 2, d.getItemBounds().getBounds().y + d.getItemBounds().getBounds().height, d.getItemBounds().getBounds().width, 2 );
  936.                     g.fillRect( d.getItemBounds().getBounds().x + d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().y + 2, 2, d.getItemBounds().getBounds().height );
  937.                     
  938.                     // Set current menu.
  939.                     this.activeMenu = i;
  940.  
  941.                     // Once found, we're done.
  942.                     break;
  943.                 }
  944.             }
  945.         }
  946.     }
  947.         
  948.     public void mouseReleased( MouseEvent e ) {
  949.         Graphics g = this.getGraphics();
  950.         FontMetrics theFontMetrics = g.getFontMetrics();
  951.  
  952.         // Handle redraw of current menu.
  953.         if ( this.activeMenu != -1 ) {
  954.             // Get menu object.
  955.             int i = this.activeMenu;
  956.             DesktopMenu d = ( DesktopMenu )dmb.getVector().elementAt( i );
  957.  
  958.             doFlashMenuItem( d );
  959.             
  960.             // Get menu item vector.
  961.             Vector v = d.getVector();
  962.  
  963.             // Redraw desktop background behind this menu.
  964.             g.setColor( Color.lightGray );
  965. //            g.fillRect( d.getX() - Global.defaultMenuHSep, this.getY() + this.getMenuBarHeight(), tempWidth + ( 2 * Global.defaultMenuHSep ), v.size() * theFontMetrics.getHeight() );
  966.             g.fillRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );
  967.  
  968.             g.drawRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );
  969.             g.fillRect( d.getItemBounds().getBounds().x + 2, d.getItemBounds().getBounds().y + d.getItemBounds().getBounds().height, d.getItemBounds().getBounds().width, 2 );
  970.             g.fillRect( d.getItemBounds().getBounds().x + d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().y + 2, 2, d.getItemBounds().getBounds().height );
  971.  
  972.             // Redraw menubar background behind this menu.
  973.             g.setColor( dmb.getBackground() );
  974.             g.fillRect( d.getX() - Global.defaultMenuHSep, this.getY(), ( d.getLabel() == null ? ( ( DesktopImageMenu )d ).getImage().getWidth( this ) : theFontMetrics.stringWidth( d.getLabel() ) ) + ( 2 * Global.defaultMenuHSep ), getMenuBarHeight() );
  975.             g.setColor( Color.black );
  976.             
  977.             // Draw menu String or Image.
  978.             if ( d.getLabel() != null )
  979.                 g.drawString( d.getLabel(), d.getX(), d.getY() );
  980.             else
  981.                 g.drawImage( ( ( DesktopImageMenu )d ).getImage(), d.getX(), d.getY(), this );
  982.                 
  983. //            String s = ( ( DesktopMenuItem )d.getVector().elementAt( this.activeMenuItem ) ).getLabel();
  984.             this.handleMenuItem();
  985.  
  986.             // No active menu.
  987.             this.activeMenu = -1;
  988.             this.activeMenuItem = -1;
  989.             activeMenuRect = new Rectangle( -1, -1, 0, 0 );
  990.             activeMenuItemRect = new Rectangle( -1, -1, 0, 0 );
  991.         }
  992.         else if ( this.dragItem != null && this.dragInProgress ) {
  993.             if ( this.highlightedImage != null && this.highlightedImage.getImage() != null ) {
  994.                 Rectangle r;
  995.                 if ( this.highlightedImage.getImage() != null )
  996.                     r = new Rectangle( this.highlightedImage.getBounds().x, this.highlightedImage.getBounds().y, this.highlightedImage.getImage().getWidth( this ), this.highlightedImage.getImage().getHeight( this ) );
  997.                 else
  998.                     r = new Rectangle( this.highlightedImage.getBounds().x, this.highlightedImage.getBounds().y, this.highlightedImage.getBounds().width, this.highlightedImage.getBounds().height );
  999.  
  1000.                 if ( r.contains( e.getX(), e.getY() ) ) {
  1001.                     // Move folder
  1002.                     String path = this.highlightedImage.getPath();
  1003.                     if ( path != null ) {
  1004.                         File f = new File( path );
  1005.                         if ( f.exists() && f.isDirectory() ) {
  1006.                             if ( this.dragItem != this.vectorImages.elementAt( 1 ) ) {
  1007.     //                            System.out.println( "Oops!" );
  1008.                                 File fSource = new File( this.dragItem.getPath() );
  1009.                                 boolean b = this.moveItem( fSource, f );
  1010.                                 this.vectorImages.removeElement( this.dragItem );
  1011.                 
  1012.                                 for ( int j = 0; j < vectorWindows.size(); j++ ) {
  1013.                                     DesktopFrame d = ( DesktopFrame )vectorWindows.elementAt( j );
  1014.                                     if ( d.getPath() == this.dragItem.getPath() ) {
  1015.                                         d.setVisible( false );
  1016.                                         this.vectorWindows.removeElementAt( j );
  1017.                                     }
  1018.                                 }
  1019.                                 
  1020.                                 if ( this.highlightedImage.getImage() == ( ( DesktopImage )this.vectorImages.elementAt( 0 ) ).getImage() ) {
  1021. //                                if ( this.highlightedImage.getImage() == this.imgTrash.getImage() || this.highlightedImage.getImage() == this.imgTrashFull.getImage() ) {
  1022.                                     r = ( ( DesktopImage )this.vectorImages.elementAt( 0 ) ).getBounds();
  1023.                                     this.vectorImages.setElementAt( this.imgTrashFull, 0 );
  1024.                                     ( ( DesktopImage )this.vectorImages.elementAt( 0 ) ).setBounds( r );
  1025.                                     this.repaint();
  1026.                                 }
  1027.                             }
  1028.                             else
  1029.                                 System.out.println( "Cannot move root volume." );
  1030.                         }
  1031.                     }        
  1032.                 }
  1033.             }
  1034.  
  1035.             this.dragItem.setLocation( e.getX() - this.initialX, e.getY() - this.initialY );
  1036.             this.dragItem.setLabelLocation( this.dragItem.getX() + ( this.dragItem.getImage().getWidth( this ) / 2 ) - ( this.getGraphics().getFontMetrics().stringWidth( this.dragItem.getLabel() ) / 2 ), this.dragItem.getY() + ( this.dragItem.getImage().getHeight( this ) ) + ( this.getGraphics().getFontMetrics().getHeight() ) );
  1037.             this.initialX = 0;
  1038.             this.initialY = 0;
  1039.             this.dragInProgress = false;
  1040.             this.dragItem = null;
  1041.             this.highlightedImage = null;
  1042.  
  1043. //    Unchanged.
  1044.             this.repaint();
  1045.         }
  1046.     }
  1047.     
  1048. //    public boolean handleMenuItem( String s ) {
  1049.     public boolean handleMenuItem() {
  1050.         boolean returnValue = false;
  1051.  
  1052.         // Handle active menu item.
  1053.         if ( ( this.activeMenu != -1 ) && ( this.activeMenuItem != -1 ) ) {
  1054.             // Get menu object.
  1055.             DesktopMenu dm = ( DesktopMenu )dmb.getVector().elementAt( this.activeMenu );
  1056.             
  1057.             // Get menu item.
  1058.             String s = ( ( DesktopMenuItem )dm.getVector().elementAt( this.activeMenuItem ) ).getLabel();
  1059.  
  1060.             // Handle shutdown menu item.
  1061.             if ( s.equals( Global.menuItemShutdown ) ) {
  1062.                 this.saveState();
  1063.                 System.exit( 0 );
  1064.                 returnValue = true;
  1065.             }
  1066.             // Handle About... menu item.
  1067.             else if ( s.equals( Global.menuItemNew ) ) {
  1068.                 boolean done = false;
  1069.                 int i = -1;
  1070.                 
  1071.                 DesktopImage di = ( ( DesktopImage )this.vectorImages.elementAt( 1 ) );
  1072.                 String path = di.getPath();
  1073.                 StringBuffer sb = new StringBuffer();
  1074.                 File f = new File( path, sb.toString() );
  1075.  
  1076.                 while ( !done ) {
  1077.                     sb.append( Global.newItemName );
  1078.  
  1079.                     if ( i >= 0 )
  1080.                         sb.append( Global.newItemCopyName );
  1081.  
  1082.                     if ( i > 0 )
  1083.                         sb.append( " " + i );
  1084.  
  1085.                     i++;
  1086.  
  1087.                     f = new File( path, sb.toString() );
  1088.         
  1089.                     if ( !f.exists() ) {
  1090.                         boolean b = f.mkdir();
  1091.                         done = true;
  1092.                         break;
  1093.                     }
  1094.  
  1095.                     sb = new StringBuffer();
  1096.                 }
  1097.  
  1098.                 DesktopImage d = new DesktopImage();
  1099.                 d.setLabel( sb.toString() );
  1100.                 d.setPath( f.getPath() );
  1101.                 d.setImage( imgFolder.getImage() );
  1102.                 d.setLocation( di.getBounds().x, di.getBounds().y + ( di.getImage().getHeight( this ) * 3 ) );
  1103.                 d.setLabelLocation( d.getX() + ( d.getImage().getWidth( this ) / 2 ) - ( this.getGraphics().getFontMetrics().stringWidth( d.getLabel() ) / 2 ), d.getY() + ( d.getImage().getHeight( this ) ) + ( this.getGraphics().getFontMetrics().getHeight() ) );
  1104.                 d.addMouseListener( this );
  1105.                 this.vectorImages.addElement( d );
  1106.                 this.repaint();
  1107.             }
  1108.             else if ( s.equals( Global.menuItemEmptyTrash ) ) {
  1109.                 DesktopImage di = ( ( DesktopImage )this.vectorImages.elementAt( 1 ) );
  1110.                 String path = di.getPath();
  1111.                 File f = new File( path, Global.trashDisplayString );
  1112.                 if ( f.exists() && f.isDirectory() ) {
  1113.                     boolean b = this.emptyDir( f );
  1114.                     if ( b ) {
  1115.                         Rectangle r = ( ( DesktopImage )this.vectorImages.elementAt( 0 ) ).getBounds();
  1116.                         this.vectorImages.setElementAt( this.imgTrash, 0 );
  1117.                         ( ( DesktopImage )this.vectorImages.elementAt( 0 ) ).setBounds( r );
  1118.                         this.repaint();
  1119.                     }
  1120.                 }
  1121.             }
  1122.             // Handle About... menu item.
  1123.             else if ( s.equals( Global.menuItemAboutMac ) ) {
  1124. //                DesktopWindow d = new DesktopWindow( new Frame() );
  1125.                 DesktopDialog d = new DesktopDialog();
  1126.                 d.setX( 100 );
  1127.                 d.setY( 100 );
  1128.                 d.setWidth( 200 );
  1129.                 d.setHeight( 100 );
  1130.                 String s1 = new String( System.getProperty( "os.name" ) + " " + System.getProperty( "os.arch" ) + " " + System.getProperty( "os.version" ) );
  1131.                 d.setLabel( s1 );
  1132.                 //System.getProperty( "os.name" ) + " " + System.getProperty( "os.arch" ) + " " + System.getProperty( "os.version" ) );
  1133.                 d.show();
  1134.                 d.toFront();
  1135.                 d.paint( this.getGraphics() );
  1136.  
  1137.                 this.doDelay();
  1138.                 this.repaint();
  1139.                 returnValue = true;
  1140.             }
  1141.         }
  1142.         
  1143.         return returnValue;
  1144.     }
  1145.     
  1146.     public boolean moveItem( File f, File dir ) {
  1147.         // Recursive method to move a directory's contents,
  1148.         // then delete the directory.
  1149.         boolean retVal = false;
  1150.         
  1151.         String name = f.getName();
  1152.         StringBuffer sb = new StringBuffer( name );
  1153.         String array[] = dir.list();
  1154.         boolean done = false, found = false;
  1155.         int i = 0;            
  1156.             
  1157.         if ( array != null ) {
  1158.             while ( !done ) {
  1159.                 found = false;
  1160.                 
  1161.                 for ( int count = 0; count < array.length; count ++ ) {
  1162.                     String temp = array[ count ];
  1163.                     if ( temp.equals( sb.toString() ) ) {
  1164.                         found = true;
  1165.                         break;
  1166.                     }
  1167.                 }
  1168.  
  1169.                 if ( found ) {
  1170.                     if ( i >= 0 )
  1171.                         sb.append( Global.newItemCopyName );
  1172.  
  1173.                     if ( i > 0 )
  1174.                         sb.append( " " + i );
  1175.  
  1176.                     i++;
  1177.                 }
  1178.                 else
  1179.                     done = true;
  1180.             }
  1181.         }
  1182.             
  1183.         File fNew = new File( dir.getPath(), sb.toString() );
  1184.  
  1185.         if ( f.isFile() ) {
  1186.             try {
  1187.                 FileOutputStream fos = new FileOutputStream( fNew );
  1188.                 DataOutputStream dos = new DataOutputStream( fos );
  1189.  
  1190.                 FileInputStream fis = new FileInputStream( f );
  1191.                 DataInputStream dis = new DataInputStream( fis );
  1192.                 
  1193.                 int offset = 0;
  1194.                 int size = 64;
  1195.                 byte[] b = new byte[ size ];
  1196.                 
  1197.                 while ( dis.available() > 0 ) {
  1198.                     if ( dis.available() < size ) {
  1199.                         size = dis.available();
  1200.                         b = new byte[ size ];
  1201.                     }
  1202.                     
  1203.                     int amount = dis.read( b );
  1204.                     if ( amount <= 0 )
  1205.                         break;
  1206.  
  1207.                     dos.write( b );
  1208.                     
  1209.                     offset += amount;
  1210.                 }
  1211.             
  1212.                 dos.flush();
  1213.                 
  1214.                 dos.close();
  1215.                 fos.close();
  1216.                 
  1217.                 dis.close();
  1218.                 fis.close();
  1219.                 
  1220.                 f.delete();
  1221.                 
  1222.                 retVal = true;
  1223.             }
  1224.             catch ( IOException e ) {
  1225.                 System.out.println( "IOException moving file..." );
  1226.             }
  1227.         }
  1228.         else if ( f.isDirectory() ) {
  1229.             array = f.list();
  1230.             retVal = fNew.mkdirs();
  1231.     
  1232.             if ( array != null /*&& array.length > 0*/ ) {
  1233.                 for ( int count = 0; count < array.length; count ++ ) {
  1234.                     String temp = array[ count ];
  1235.                     File f2 = new File( f, temp );
  1236.                     
  1237. //                    if ( f2.isFile() )
  1238.                         retVal = this.moveItem( f2, fNew );
  1239. //                    else if ( f2.isDirectory() )
  1240. //                        retVal = fNew.mkdirs();
  1241.                 }
  1242.             }
  1243.             
  1244.             if ( retVal ) {
  1245.                 retVal = this.emptyDir( f, true );
  1246.                 retVal = f.delete();
  1247.             }
  1248.         }
  1249.  
  1250.         return retVal;
  1251.     }
  1252.     
  1253.     public boolean emptyDir( File dir ) {
  1254.         // Recursive method to remove a directory's contents,
  1255.         // then delete the directory.
  1256.         boolean b = false;
  1257.         
  1258.         String array[] = dir.list();
  1259.             
  1260.         if ( array != null ) {
  1261.             for ( int count = 0; count < array.length; count ++ ) {
  1262.                 String temp = array[ count ];
  1263.                 File f1 = new File( dir, temp );
  1264.                 
  1265.                 if ( f1.isFile() ) {
  1266.                     b = f1.delete();
  1267.                 }
  1268.                 else if ( f1.isDirectory() ) {
  1269.                     b = this.emptyDir( f1 );
  1270.                     b = f1.delete();
  1271. //if ( !b ) System.out.println( "Cannot delete " + f1.toString() );
  1272.                 }
  1273.             }
  1274.         }
  1275.  
  1276.         return b;
  1277.     }
  1278.     
  1279.     public boolean emptyDir( File dir, boolean remove ) {
  1280.         // Recursive method to remove a directory's contents,
  1281.         // then delete the directory.
  1282.         boolean b = false;
  1283.         
  1284.         String array[] = dir.list();
  1285.             
  1286.         if ( array != null ) {
  1287.             for ( int count = 0; count < array.length; count ++ ) {
  1288.                 String temp = array[ count ];
  1289.                 File f1 = new File( dir, temp );
  1290.                 
  1291.                 if ( f1.isFile() )
  1292.                     b = f1.delete();
  1293.                 else if ( f1.isDirectory() ) {
  1294.                     b = this.emptyDir( f1, remove );
  1295.                     
  1296.                     if ( remove )
  1297.                         f1.delete();
  1298.                     
  1299. //if ( !b ) System.out.println( "Cannot delete " + f1.toString() );
  1300.                 }
  1301.             }
  1302.         }
  1303.  
  1304.         return b;
  1305.     }
  1306.     
  1307.     public void redrawOpenFrames() {
  1308.         // Draw windows.
  1309.         Enumeration e = this.vectorWindows.elements();
  1310.  
  1311.         while ( e.hasMoreElements() ) {
  1312.             DesktopFrame d = ( DesktopFrame )e.nextElement();
  1313.             
  1314.             d.repaint();
  1315.         }
  1316.     }
  1317.     
  1318.     public void paint( Graphics g2 ) {
  1319. //    public void paint( Graphics g ) {
  1320.         FontMetrics theFontMetrics = g.getFontMetrics();
  1321.  
  1322.         // Draw splash image.
  1323.         if ( this.bSplash ) {
  1324.             g.drawImage( imgSplash.getImage(), this.getX() + ( ( this.getWidth() / 2 ) - ( imgSplash.getImage().getWidth( this ) / 2 ) ), this.getY() + ( ( this.getHeight() / 2 ) - ( imgSplash.getImage().getHeight( this ) / 2 ) ), this );
  1325.             g.setColor( Color.black );
  1326.             g.drawString( Global.splashDisplayString, this.getX() + ( this.getWidth() / 2 ) - ( theFontMetrics.stringWidth( Global.splashDisplayString ) / 2 ), this.getY() + ( ( this.getHeight() / 2 ) + ( imgSplash.getImage().getHeight( this ) / 2 ) ) - ( 3 * theFontMetrics.getHeight() ) );
  1327.             g.drawString( Global.startupDisplayString, this.getX() + ( this.getWidth() / 2 ) - ( theFontMetrics.stringWidth( Global.startupDisplayString ) / 2 ), this.getY() + ( ( this.getHeight() / 2 ) + ( imgSplash.getImage().getHeight( this ) / 2 ) ) - ( 2 * theFontMetrics.getHeight() ) );
  1328. //            this.bSplash = false;
  1329.  
  1330. g2.drawImage( offscreenImage, 0, 0, this );
  1331.  
  1332.             return;
  1333.         }
  1334.  
  1335.         // Draw menubar.
  1336.         g.setColor( dmb.getBackground() );
  1337.         g.fillRect( dmb.getX(), dmb.getY(), dmb.getWidth(), dmb.getHeight() );
  1338.  
  1339. //        dmb.repaint();
  1340.         
  1341.         // Draw desktop background.
  1342.         g.setColor( Color.lightGray );
  1343.         g.fillRect( this.getX(), this.getMenuBarHeight(), this.getWidth(), this.getHeight() - this.getMenuBarHeight() );
  1344.  
  1345.         g.setColor( Color.black );
  1346.  
  1347.         // Draw images.
  1348.         Enumeration e = this.vectorImages.elements();
  1349.  
  1350.         g.setFont( this.iconFont );
  1351.         theFontMetrics = g.getFontMetrics();
  1352.  
  1353.         while ( e.hasMoreElements() ) {
  1354.             DesktopImage d = ( DesktopImage )e.nextElement();
  1355.             g.drawImage( d.getImage(), d.getX(), d.getY(), this );
  1356.             g.setColor( Color.black );
  1357.             if( d.getImage() == this.imgTrash.getImage() || d.getImage() == this.imgTrashFull.getImage() ) {
  1358.                 g.setColor( Color.white );
  1359.                 g.fillRect( d.getX() - 1, d.getY() + ( d.getImage().getHeight( this ) ) + 1, theFontMetrics.stringWidth( d.getLabel() ) + 2, theFontMetrics.getHeight() - theFontMetrics.getLeading() + 2 );
  1360.                 g.setColor( Color.black );
  1361.                 g.drawString( d.getLabel(), d.getX(), d.getY() + ( d.getImage().getHeight( this ) ) + ( theFontMetrics.getAscent() ) + 1 );
  1362.             }
  1363.             else {
  1364.                 g.setColor( Color.white );
  1365.                 g.fillRect( d.getX() + ( d.getImage().getWidth( this ) / 2 ) - ( theFontMetrics.stringWidth( d.getLabel() ) / 2 ) - 1, d.getY() + ( d.getImage().getHeight( this ) ) + 1, theFontMetrics.stringWidth( d.getLabel() ) + 2, theFontMetrics.getHeight() - theFontMetrics.getLeading() + 2 );
  1366.                 g.setColor( Color.black );
  1367.                 g.drawString( d.getLabel(), d.getX() + ( d.getImage().getWidth( this ) / 2 ) - ( theFontMetrics.stringWidth( d.getLabel() ) / 2 ), d.getY() + ( d.getImage().getHeight( this ) ) + ( theFontMetrics.getAscent() ) + 1 );
  1368.             }
  1369.         }
  1370.  
  1371.         g.setFont( this.menuFont );
  1372.         theFontMetrics = g.getFontMetrics();
  1373.  
  1374.         // Draw menus.
  1375.         e = this.dmb.getVector().elements();
  1376.  
  1377.         while ( e.hasMoreElements() ) {
  1378.             DesktopMenu d = ( DesktopMenu )e.nextElement();
  1379.  
  1380.             if ( d.getLabel() != null )
  1381.                 g.drawString( d.getLabel(), d.getX(), d.getY() );
  1382.             else
  1383.                 g.drawImage( ( ( DesktopImageMenu )d ).getImage(), d.getX(), d.getY(), this );
  1384.         }
  1385.         
  1386. //if ( this.activeMenu == -1 ) {
  1387. //return;    
  1388.  
  1389.         // Draw windows.
  1390.         e = this.vectorWindows.elements();
  1391.  
  1392.         while ( e.hasMoreElements() ) {
  1393.             DesktopFrame d = ( DesktopFrame )e.nextElement();
  1394.             d.setVisible( true );
  1395.  
  1396.             d.repaint();
  1397.         }
  1398. //}
  1399.  
  1400. g2.drawImage( offscreenImage, 0, 0, this );
  1401.     }
  1402.     
  1403.     public static boolean windowExists( String s ) {
  1404. //System.out.println( "DEBUG: Incoming path = " + s );
  1405.         boolean found = false;
  1406.         int i = 0;
  1407.         
  1408.         while ( i < vectorWindows.size() ) {
  1409.             DesktopFrame d = ( DesktopFrame )vectorWindows.elementAt( i );
  1410. //System.out.println( "DEBUG: d.getPath() = " + d.getPath() );
  1411.             if ( d.getPath().equalsIgnoreCase( s ) ) {
  1412.                 Desktop.setTopFrame( d );
  1413. //                d.toFront();
  1414. //                d.repaint();
  1415.                 found = true;
  1416.                 break;
  1417.             }
  1418.             
  1419.             i++;
  1420.         }
  1421.  
  1422.         return found;
  1423.     }
  1424.     
  1425.     public static void setTopFrame( DesktopFrame d ) {
  1426.         boolean found = false;
  1427.         int i = 0;
  1428.         
  1429.         while ( i < vectorWindows.size() ) {
  1430.             if ( vectorWindows.elementAt( i ) == d ) {
  1431.                 d.toFront();
  1432.                 d.repaint();
  1433.                 found = true;
  1434.                 break;
  1435.             }
  1436.             
  1437.             i++;
  1438.         }
  1439.  
  1440.         if ( !found )
  1441.             return;
  1442.             
  1443.         DesktopFrame temp = ( DesktopFrame )vectorWindows.elementAt( i );
  1444.         
  1445.         while ( i < vectorWindows.size() - 1 ) {
  1446.             vectorWindows.setElementAt( vectorWindows.elementAt( i + 1 ), i );
  1447.             i++;
  1448.         }
  1449.  
  1450.         vectorWindows.setElementAt( temp, vectorWindows.size() - 1 );
  1451.     }
  1452.  
  1453.     public static void setTopFrame( String s ) {
  1454.         boolean found = false;
  1455.         int i = 0;
  1456.         
  1457.         while ( i < vectorWindows.size() ) {
  1458.             DesktopFrame d = ( DesktopFrame )vectorWindows.elementAt( i );
  1459.             if ( d.getPath().equals( s ) ) {
  1460.                 d.toFront();
  1461.                 d.repaint();
  1462.                 found = true;
  1463.                 break;
  1464.             }
  1465.             
  1466.             i++;
  1467.         }
  1468.  
  1469.         if ( !found )
  1470.             return;
  1471.             
  1472.         DesktopFrame temp = ( DesktopFrame )vectorWindows.elementAt( i );
  1473.         
  1474.         while ( i < vectorWindows.size() - 1 ) {
  1475.             vectorWindows.setElementAt( vectorWindows.elementAt( i + 1 ), i );
  1476.             i++;
  1477.         }
  1478.  
  1479.         vectorWindows.setElementAt( temp, vectorWindows.size() - 1 );
  1480.     }
  1481.  
  1482.     public static void adjustClipRect( Rectangle r ) {
  1483.         tempClipRect.setBounds( r.getBounds().x, r.getBounds().y, r.getBounds().width, r.getBounds().height );
  1484. //        this.getGraphics().clipRect( r.getBounds().x, r.getBounds().y, r.getBounds().width, r.getBounds().height );
  1485.     }
  1486.  
  1487.     public void update( Graphics g ) {
  1488. //        g.clipRect( tempClipRect.getBounds().x, tempClipRect.getBounds().y, tempClipRect.getBounds().width, tempClipRect.getBounds().height );
  1489.         paint( g );
  1490.     }
  1491.  
  1492. /*
  1493.     public DesktopWindow getActiveWindow() {
  1494.         return this.activeWindow;
  1495.     }
  1496.  
  1497.     public void setActiveWindow( DesktopWindow d ) {
  1498.         this.activeWindow = d;
  1499.     }
  1500. */
  1501.     public void setX( int i ) {
  1502.         this.setLocation( i, this.getLocation().y );
  1503.     }
  1504.  
  1505.     public int getX() {
  1506.         return this.getLocation().x;
  1507.     }
  1508.  
  1509.     public void setY( int i ) {
  1510.         this.setLocation( this.getLocation().x, i );
  1511.     }
  1512.  
  1513.     public int getY() {
  1514.         return this.getLocation().y;
  1515.     }
  1516.  
  1517.     public void setWidth( int i ) {
  1518.         this.setSize( i, this.getSize().height );
  1519.     }
  1520.  
  1521.     public int getWidth() {
  1522.         return this.getSize().width;
  1523.     }
  1524.  
  1525.     public void setHeight( int i ) {
  1526.         this.setSize( this.getSize().width, i );
  1527.     }
  1528.  
  1529.     public int getHeight() {
  1530.         return this.getSize().height;
  1531.     }
  1532.  
  1533.     public void setMenuBarHeight( int i) {
  1534.         this.menuBarHeight = i;
  1535.     }
  1536.  
  1537.     public int getMenuBarHeight() {
  1538.         return this.menuBarHeight;
  1539.     }
  1540.  
  1541.     public static Image getImgDoc() {
  1542.         return ( ( Image )vectorUtil.elementAt( 0 ) );
  1543.     }
  1544.  
  1545.     public static Image getImgFolder() {
  1546.         return ( ( Image )vectorUtil.elementAt( 1 ) );
  1547.     }
  1548.  
  1549.     public int drawIcon( Image theImage, int x, int y ) {
  1550.         this.getGraphics().drawImage( theImage, x, y, this );
  1551.         return( theImage.getWidth( this ) );
  1552.     }
  1553. /*    
  1554.     public static void addIcon( DesktopFrameItem d ) {
  1555.         boolean found = false;
  1556.         
  1557.         for ( int i = 0; i < vectorIcons.size(); i++ ) {
  1558.             if ( vectorIcons.elementAt( i ) == d ) {
  1559.                 found = true;
  1560.             }
  1561.         }
  1562.         
  1563.         if ( !found ) {
  1564.             vectorIcons.addElement( d );
  1565.         }
  1566.     }
  1567. */
  1568.     public static void addWindow( DesktopFrame d ) {
  1569.         boolean found = false;
  1570.         
  1571.         for ( int i = 0; i < vectorWindows.size(); i++ ) {
  1572.             if ( vectorWindows.elementAt( i ) == d ) {
  1573.                 ( ( Window )vectorWindows.elementAt( i ) ).toFront();
  1574.                 Desktop.setTopFrame( d );
  1575.                 found = true;
  1576.             }
  1577.         }
  1578.         
  1579.         if ( !found ) {
  1580.             vectorWindows.addElement( d );
  1581.         }
  1582.     }
  1583.     
  1584.     public static void removeWindow( DesktopFrame d ) {
  1585.         for ( int i = 0; i < vectorWindows.size(); i++ ) {
  1586.             if ( vectorWindows.elementAt( i ) == d ) {
  1587.                 vectorWindows.removeElementAt( i );
  1588.             }
  1589.         }
  1590.     }
  1591.     
  1592.     public void doDelayShort() {
  1593.         int delay = 0;
  1594.         Timer t1 = new Timer();
  1595.         t1.addListener( this );
  1596.         while ( delay < 1 );
  1597.         t1.removeListener( this );
  1598.     }
  1599.     
  1600.     public void doDelay() {
  1601.         this.delay = 0;
  1602.         Timer t1 = new Timer();
  1603.         t1.addListener( this );
  1604.         while ( delay < Global.splashDelay ) {
  1605.             ;
  1606.         }
  1607.         
  1608.         this.delay = 0;
  1609.         t1.removeListener( this );
  1610.     }
  1611.     
  1612.     public void doDelay( int i ) {
  1613.         // Note: i will cause a delay of ( i <seconds> * Global.splashDelay ).
  1614.         this.delay = 0;
  1615.         Timer t1 = new Timer( i );
  1616.         t1.addListener( this );
  1617.         while ( delay < Global.splashDelay );
  1618.         this.delay = 0;
  1619.         t1.removeListener( this );
  1620.     }
  1621.     
  1622.     public void doMenuDelay() {
  1623.         // Note: i will cause a delay of ( i <seconds> * Global.splashDelay ).
  1624.  
  1625.         Calendar c = Calendar.getInstance();
  1626.         Calendar old = Calendar.getInstance();
  1627.         
  1628.         old.add( Calendar.MILLISECOND, Global.menuDelayMillis );
  1629.         
  1630.         while ( !c.after( old ) ) {
  1631.             c = Calendar.getInstance();
  1632.         }
  1633.     }
  1634.     
  1635.     public void timerExpired( TimerEvent evt ) {
  1636.         this.delay++;
  1637.     }
  1638.  
  1639.     public boolean checkTrashExists() {
  1640.         DesktopImage di = ( ( DesktopImage )this.vectorImages.elementAt( 1 ) );
  1641.         String path = di.getPath();
  1642.         String s = new String( Global.trashDisplayString );
  1643.         File f = new File( path, s );
  1644.         boolean retVal = false;
  1645.         
  1646.         if ( f.exists() )
  1647.             retVal = true;
  1648.             
  1649.         if ( retVal ) {
  1650.             di = ( ( DesktopImage )this.vectorImages.elementAt( 0 ) );
  1651.             di.setPath( f.toString() );
  1652.         }
  1653.         
  1654.         return retVal;
  1655.     }
  1656.     
  1657.     public boolean createTrashDir() {
  1658.         DesktopImage di = ( ( DesktopImage )this.vectorImages.elementAt( 1 ) );
  1659.         String path = di.getPath();
  1660.         String s = new String( Global.trashDisplayString );
  1661.         File f = new File( path, s );
  1662.         boolean retVal = false;
  1663.             
  1664.         retVal = f.mkdir();
  1665.  
  1666.         if ( retVal ) {
  1667.             di = ( ( DesktopImage )this.vectorImages.elementAt( 0 ) );
  1668.             di.setPath( f.toString() );
  1669.         }
  1670.         
  1671.         return retVal;
  1672.     }
  1673.     
  1674.     public void doFlashMenuItem( DesktopMenu d ) {
  1675.         Graphics g = this.getGraphics();
  1676.         
  1677.         if ( ( this.activeMenu != -1 ) && ( this.activeMenuItem != -1 ) ) {
  1678.             // Get menu item vector.
  1679.             Vector v = d.getVector();
  1680.  
  1681.             // Unhighlight current menu item.
  1682.             // If Point is outside menu item, redraw the menu item.
  1683.             for ( int i = 0; i < 3; i++ ) {
  1684.                 // Redraw menu background behind this menu item.
  1685.                 g.setColor( dmb.getBackground() );
  1686.                 g.fillRect( activeMenuItemRect.x, activeMenuItemRect.y, activeMenuItemRect.width, activeMenuItemRect.height );
  1687.  
  1688.                 g.setColor( Color.black );
  1689.                 g.drawRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );
  1690. //                g.fillRect( d.getItemBounds().getBounds().x + 2, d.getItemBounds().getBounds().y + d.getItemBounds().getBounds().height, d.getItemBounds().getBounds().width, 2 );
  1691. //                g.fillRect( d.getItemBounds().getBounds().x + d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().y + 2, 2, d.getItemBounds().getBounds().height );
  1692.  
  1693.                 // Redraw menu item.
  1694.                 g.setColor( Color.black );
  1695.                 g.drawString( ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getLabel(), ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getDrawPoint().x, ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getDrawPoint().y );
  1696.  
  1697.                 this.doMenuDelay();
  1698.  
  1699.                 // Redraw menu background behind this menu item.
  1700.                 g.setColor( Color.blue );
  1701.                 g.fillRect( activeMenuItemRect.x, activeMenuItemRect.y, activeMenuItemRect.width, activeMenuItemRect.height );
  1702.  
  1703.                 g.setColor( Color.black );
  1704.                 g.drawRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );
  1705.  
  1706.                 // Redraw menu item.
  1707.                 g.setColor( Color.white );
  1708.                 g.drawString( ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getLabel(), ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getDrawPoint().x, ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getDrawPoint().y );
  1709.  
  1710.                 this.doMenuDelay();
  1711.             }
  1712.         }
  1713.     }
  1714.  
  1715.     private void saveState() {
  1716.         DesktopImage di = ( ( DesktopImage )this.vectorImages.elementAt( 1 ) );
  1717.         String s = new String( di.getPath() + "Desktop.ser" );
  1718.         try {
  1719.             FileOutputStream fos = new FileOutputStream( s );
  1720.             ObjectOutputStream outStream = new ObjectOutputStream( fos );
  1721.             Vector v = new Vector();
  1722.             v = ( Vector )this.vectorWindows.clone();
  1723.  
  1724.             Vector temp = new Vector();
  1725.             
  1726.             for ( int i = 0; i < v.size(); i++ ) {
  1727.                 DesktopFrame df = ( DesktopFrame )v.elementAt( i );
  1728.                 temp.addElement( df.getPath() );
  1729.                 temp.addElement( df.getLabel() );
  1730.                 
  1731.                 if ( df.getShade() ) {
  1732.                     df.restoreHeight();
  1733.                 }
  1734.                 
  1735.                 temp.addElement( df.getBounds() );
  1736.             }
  1737.  
  1738.             outStream.writeObject( temp );
  1739.  
  1740.             temp = new Vector();
  1741.  
  1742.             v = new Vector();
  1743.             v = ( Vector )this.vectorImages.clone();
  1744.  
  1745.             for ( int i = 2; i < v.size(); i++ ) {
  1746.                 DesktopImage d = ( DesktopImage )v.elementAt( i );
  1747.                 temp.addElement( d.getPath() );
  1748.                 temp.addElement( d.getLabel() );
  1749.                 temp.addElement( d.getBounds() );
  1750.             }
  1751.  
  1752.             outStream.writeObject( temp );
  1753.  
  1754.             outStream.flush();
  1755.             outStream.close();
  1756.         }
  1757.         catch ( IOException e ) {
  1758.             System.out.println( "Couldn't save state." );
  1759.             System.out.println( "s = " + s );
  1760.             e.printStackTrace();
  1761.         }
  1762.     }
  1763.  
  1764.     private void restoreState() {
  1765.         DesktopImage di = ( ( DesktopImage )this.vectorImages.elementAt( 1 ) );
  1766.         String s = new String( "\\Desktop.ser" );
  1767. //        String s = new String( di.getPath() + "Desktop.ser" );
  1768.         try {
  1769.             FileInputStream fis = new FileInputStream( s );
  1770.             ObjectInputStream inStream = new ObjectInputStream( fis );
  1771.             Vector v = new Vector();
  1772.             v = ( Vector )inStream.readObject();
  1773.             
  1774.             Rectangle r = new Rectangle();
  1775.             
  1776.             for ( int i = 0; i < v.size(); i++ ) {
  1777.                 s = ( String )v.elementAt( i );
  1778.                 
  1779.                 DesktopFrame df = new DesktopFrame( s );
  1780.     
  1781.                 i++;
  1782.                 s = ( String )v.elementAt( i );
  1783.                 df.setLabel( s );
  1784.  
  1785.                 i++;
  1786.                 r = ( Rectangle )v.elementAt( i );
  1787.                 df.setBounds( r );
  1788.                 
  1789.                 df.pack();
  1790.                 df.validate();
  1791.                 df.show();
  1792.                 df.toFront();
  1793.                 df.repaint();
  1794.             }
  1795.  
  1796.             v = new Vector();
  1797.             v = ( Vector )inStream.readObject();
  1798.  
  1799.             for ( int i = 0; i < v.size(); i++ ) {
  1800.                 DesktopImage d = new DesktopImage();
  1801.                 
  1802.                 s = ( String )v.elementAt( i );
  1803.                 d.setPath( s );
  1804.                     
  1805.                 i++;
  1806.                 s = ( String )v.elementAt( i );
  1807.                 d.setLabel( s );
  1808.                 
  1809.                 i++;
  1810.                 r = ( Rectangle )v.elementAt( i );
  1811.                 d.setBounds( r );
  1812.                 
  1813.                 d.setImage( imgFolder.getImage() );
  1814.                 d.setLocation( di.getBounds().x, di.getBounds().y + ( di.getImage().getHeight( this ) * 3 ) );
  1815.                 d.setLabelLocation( d.getX() + ( d.getImage().getWidth( this ) / 2 ) - ( this.getGraphics().getFontMetrics().stringWidth( d.getLabel() ) / 2 ), d.getY() + ( d.getImage().getHeight( this ) ) + ( this.getGraphics().getFontMetrics().getHeight() ) );
  1816.                 d.addMouseListener( this );
  1817.                 this.vectorImages.addElement( d );
  1818.             }
  1819.  
  1820.             inStream.close();
  1821.         }
  1822.         catch ( ClassNotFoundException e ) {
  1823.             System.out.println( "ClassNotFoundException in retrieveState()." );
  1824.         }
  1825.         catch ( IOException e ) {
  1826.             System.out.println( "Couldn't retrieve state." );
  1827.             System.out.println( "s = " + s );
  1828.             e.printStackTrace();
  1829.         }
  1830.     }
  1831. }
  1832.  
  1833.